package com.ruoyi.web.controller.weiriya;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.entity.WMember;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.weiriya.domain.WVipSetting;
import com.ruoyi.weiriya.service.IWMemberService;
import com.ruoyi.weiriya.service.IWMessageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.weiriya.domain.WNonVipSetting;
import com.ruoyi.weiriya.service.IWNonVipSettingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 非会员购买设置Controller
 * 
 * @author lynn
 * @date 2023-08-01
 */
@Api(tags = "非会员购买设置管理")
@RestController
@RequestMapping("/weiriya/nonVipSetting")
public class WNonVipSettingController extends BaseController
{
    @Autowired
    private IWNonVipSettingService wNonVipSettingService;

    @Autowired
    private IWMemberService memberService;

    /**
     * 查询非会员购买设置列表
     */
    @ApiOperation("获取非会员购买设置列表")
    @GetMapping("/list")
    public TableDataInfo list(WNonVipSetting wNonVipSetting)
    {
        startPage();
        List<WNonVipSetting> list = wNonVipSettingService.getList(wNonVipSetting);
        return getDataTable(list);
    }

    /**
     * 导出非会员购买设置列表
     */
    @ApiOperation("导出非会员购买设置列表")
    @Log(title = "非会员购买设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WNonVipSetting wNonVipSetting)
    {
        List<WNonVipSetting> list = wNonVipSettingService.getList(wNonVipSetting);
        ExcelUtil<WNonVipSetting> util = new ExcelUtil<WNonVipSetting>(WNonVipSetting.class);
        util.exportExcel(response, list, "非会员购买设置数据");
    }

    /**
     * 导入非会员购买设置列表
     */
    @ApiOperation("导入非会员购买设置列表")
    @Log(title = "非会员购买设置", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<WNonVipSetting> util = new ExcelUtil<WNonVipSetting>(WNonVipSetting.class);
        List<WNonVipSetting> list = util.importExcel(file.getInputStream());
        return success(wNonVipSettingService.saveBatch(list));
    }

    /**
     * 获取非会员购买设置详细信息
     */
    @ApiOperation("获取非会员购买设置详细")
    @ApiImplicitParam(name = "id", value = "非会员购买设置ID", required = true, dataType = "String", paramType = "path")
    @GetMapping(value = {"/{id}", "/{id}/{settingType}"})
    public AjaxResult getInfo(@PathVariable("id") String id, @PathVariable(value = "userId", required = false) Integer settingType)
    {
        return success(wNonVipSettingService.getWNonVipSettingById(id, settingType));
    }

    /**
     * 根据点位ID获取详细信息
     */
    @ApiOperation("根据点位ID获取详细信息")
    @ApiImplicitParam(name = "areaId", value = "点位ID", required = true, dataType = "String", paramType = "path")
    @GetMapping(value = {"/getByAreaId/{areaId}"})
    public AjaxResult getByAreaId(@PathVariable("areaId") String areaId)
    {
        return success(wNonVipSettingService.getOne(new LambdaQueryWrapper<WNonVipSetting>()
                .eq(WNonVipSetting::getAreaId, areaId)));
    }
    /**
     * 用户获取点位收费规则
     */
    @ApiOperation("用户获取点位临时收费规则")
    @GetMapping(value = {"/getByMember"})
    public AjaxResult getByMember()
    {
        WMember member = memberService.getById(SecurityUtils.getUserId());
        return success(wNonVipSettingService.getWNonVipSettingByAreaId(member.getAreaId()));
    }

    /**
     * 新增非会员购买设置
     */
    @ApiOperation("新增非会员购买设置")
    @Log(title = "非会员购买设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WNonVipSetting wNonVipSetting)
    {
        return toAjax(wNonVipSettingService.saveWNonVipSetting(wNonVipSetting));
    }

    /**
     * 修改非会员购买设置
     */
    @ApiOperation("更新非会员购买设置")
    @Log(title = "非会员购买设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WNonVipSetting wNonVipSetting)
    {
        return toAjax(wNonVipSettingService.updateWNonVipSettingById(wNonVipSetting));
    }

    /**
     * 删除非会员购买设置
     */
    @ApiOperation("删除非会员购买设置")
    @ApiImplicitParam(name = "ids", value = "非会员购买设置ID集合", required = true, dataType = "String", paramType = "path")
    @Log(title = "非会员购买设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(wNonVipSettingService.removeByIds(ids));
    }
}
